﻿using System;
using System.ServiceModel.DomainServices.Server;
using log4net;

namespace MVVMtutorialAdvanced.Web
{
	// Unit Testing a WCF RIA DomainService: Part 1, The IDomainServiceFactory
	// http://blogs.msdn.com/b/kylemc/archive/2011/08/18/unit-testing-a-wcf-ria-domainservice-part-1-the-idomainservicefactory.aspx

	// Domain Service Factory is instantiated in Global.asax.Application_Start
	public class DomainServiceFactoryRiba : IDomainServiceFactory
	{
		public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context)
		{
			var log = LogManager.GetLogger(typeof(Global));
			log.Debug("----------------- CreateDomainService");

			var domainService = new DomainServiceBook(Global.SessionFactory);
			domainService.Initialize(context);

			return domainService;
		}

		public void ReleaseDomainService(DomainService domainService)
		{
			domainService.Dispose();
		}
	}
}